package com.micro.school.system.controller.base;

import com.micro.school.common.core.context.SecurityContextHolder;
import com.micro.school.common.core.web.controller.BaseController;
import com.micro.school.common.core.web.domain.AjaxResult;
import com.micro.school.common.core.web.page.TableDataInfo;
import com.micro.school.system.domain.MerMerchant;
import com.micro.school.system.service.MerMerchantService;
import jakarta.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * (MerMerchant)表控制层
 *
 * @author makejava
 * @since 2025-08-08 19:07:07
 */
@RestController
@RequestMapping("/merMerchant")
public class MerMerchantController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private MerMerchantService merMerchantService;

    /**
     * 分页查询
     *
     * @param merMerchant 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public TableDataInfo queryByPage(MerMerchant merMerchant) {
        startPage();
        List<MerMerchant> merMerchants = this.merMerchantService.queryByPage(merMerchant);
        return getDataTable(merMerchants);
    }


    /**
     * 分页查询
     *
     * @param merMerchant 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping("/selectMerchant")
    public AjaxResult selectMerchant() {
        MerMerchant merMerchant = new MerMerchant();
        merMerchant.setTenantId(Integer.valueOf(SecurityContextHolder.getUserTenantId()));
        merMerchant.setStatus(1);
        List<MerMerchant> merMerchants = this.merMerchantService.queryByPage(merMerchant);
        return success(merMerchants);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public AjaxResult queryById(@PathVariable("id") Integer id) {
        return success(this.merMerchantService.queryById(id));
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/queryMerchantById/{id}")
    public AjaxResult queryMerchantById(@PathVariable("id") Long id) {
        return success(this.merMerchantService.queryMerchantById(id));
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/fegin/{ids}")
    public AjaxResult merMerchant(@PathVariable("ids") Integer id) {
        return success(this.merMerchantService.merMerchant(id));
    }

    /**
     * 新增数据
     *
     * @param merMerchant 实体
     * @return 新增结果
     */
    @PostMapping
    public AjaxResult add(@RequestBody MerMerchant merMerchant) {
        return success(this.merMerchantService.insert(merMerchant));
    }

    /**
     * 编辑数据
     *
     * @param merMerchant 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody MerMerchant merMerchant) {
        return success(this.merMerchantService.update(merMerchant));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public AjaxResult deleteById(Integer id) {
        return success(this.merMerchantService.deleteById(id));
    }

}

